package com.hystrix.command;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;

/**
 * 测试回退
 * Created by earl on 2018/4/28.
 */
public class FallbackCommand extends HystrixCommand<String> {

    public FallbackCommand() {
        super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
    }

    /**
     * 断路器被强制打开，该方法不会执行
     */
    @Override
    protected String run() throws Exception {
        System.out.println("命令执行");
        return "";
    }

    /**
     * 回退方法，断路器打开后会执行回退
     */
    @Override
    protected String getFallback() {
        System.out.println("执行回退方法，并回退到另外一个命令执行");
        BackupCommand backupCommand = new BackupCommand();
        return backupCommand.execute();
    }
}
